@@ -21,8 +21,8 @@ gem 'weibo_2', github: 'cantino/weibo_2', branch: 'master' |
||
| 21 | 21 |
gem "google-api-client", require: 'google/api_client' |
| 22 | 22 |
|
| 23 | 23 |
# Twitter Agents |
| 24 |
-gem 'twitter', '~> 5.8.0' # Must to be loaded before cantino-twitter-stream. |
|
| 25 |
-gem 'twitter-stream', github: 'dsander/twitter-stream', branch: 'huginn' |
|
| 24 |
+gem 'twitter', '~> 5.14.0' # Must to be loaded before cantino-twitter-stream. |
|
| 25 |
+gem 'twitter-stream', github: 'cantino/twitter-stream', branch: 'huginn' |
|
| 26 | 26 |
gem 'omniauth-twitter' |
| 27 | 27 |
|
| 28 | 28 |
# Tumblr Agents |
@@ -1,4 +1,14 @@ |
||
| 1 | 1 |
GIT |
| 2 |
+ remote: git://github.com/cantino/twitter-stream.git |
|
| 3 |
+ revision: f7e7edb0bae013bffabf3598e7147773d9fd370f |
|
| 4 |
+ branch: huginn |
|
| 5 |
+ specs: |
|
| 6 |
+ twitter-stream (0.1.15) |
|
| 7 |
+ eventmachine (~> 1.0.7) |
|
| 8 |
+ http_parser.rb (~> 0.6.0) |
|
| 9 |
+ simple_oauth (~> 0.3.0) |
|
| 10 |
+ |
|
| 11 |
+GIT |
|
| 2 | 12 |
remote: git://github.com/cantino/weibo_2.git |
| 3 | 13 |
revision: 00e57d29d8252126014b038cd738b02e05e4cfc5 |
| 4 | 14 |
branch: master |
@@ -10,16 +20,6 @@ GIT |
||
| 10 | 20 |
rest-client (~> 1.8) |
| 11 | 21 |
|
| 12 | 22 |
GIT |
| 13 |
- remote: git://github.com/dsander/twitter-stream.git |
|
| 14 |
- revision: 1713b4fe5b387580364b39716bb5c26d6601c50f |
|
| 15 |
- branch: huginn |
|
| 16 |
- specs: |
|
| 17 |
- twitter-stream (0.1.15) |
|
| 18 |
- eventmachine (~> 1.0.7) |
|
| 19 |
- http_parser.rb (~> 0.6.0) |
|
| 20 |
- simple_oauth (~> 0.2.0) |
|
| 21 |
- |
|
| 22 |
-GIT |
|
| 23 | 23 |
remote: git://github.com/wunderlist/omniauth-wunderlist.git |
| 24 | 24 |
revision: d0910d0396107b9302aa1bc50e74bb140990ccb8 |
| 25 | 25 |
ref: d0910d0396107b9302aa1bc50e74bb140990ccb8 |
@@ -67,7 +67,7 @@ GEM |
||
| 67 | 67 |
minitest (~> 5.1) |
| 68 | 68 |
thread_safe (~> 0.3, >= 0.3.4) |
| 69 | 69 |
tzinfo (~> 1.1) |
| 70 |
- addressable (2.3.7) |
|
| 70 |
+ addressable (2.3.8) |
|
| 71 | 71 |
arel (6.0.0) |
| 72 | 72 |
autoparse (0.3.3) |
| 73 | 73 |
addressable (>= 2.3.1) |
@@ -144,7 +144,7 @@ GEM |
||
| 144 | 144 |
em-websocket (0.5.1) |
| 145 | 145 |
eventmachine (>= 0.12.9) |
| 146 | 146 |
http_parser.rb (~> 0.6.0) |
| 147 |
- equalizer (0.0.9) |
|
| 147 |
+ equalizer (0.0.11) |
|
| 148 | 148 |
erector (0.10.0) |
| 149 | 149 |
treetop (>= 1.2.3) |
| 150 | 150 |
erubis (2.7.0) |
@@ -212,8 +212,8 @@ GEM |
||
| 212 | 212 |
httmultiparty (0.3.10) |
| 213 | 213 |
httparty (>= 0.7.3) |
| 214 | 214 |
multipart-post |
| 215 |
- http (0.5.1) |
|
| 216 |
- http_parser.rb |
|
| 215 |
+ http (0.6.4) |
|
| 216 |
+ http_parser.rb (~> 0.6.0) |
|
| 217 | 217 |
http-cookie (1.0.2) |
| 218 | 218 |
domain_name (~> 0.5) |
| 219 | 219 |
http_parser.rb (0.6.0) |
@@ -403,7 +403,7 @@ GEM |
||
| 403 | 403 |
jwt (>= 0.1.5) |
| 404 | 404 |
multi_json (>= 1.0.0) |
| 405 | 405 |
simple-rss (1.3.1) |
| 406 |
- simple_oauth (0.2.0) |
|
| 406 |
+ simple_oauth (0.3.1) |
|
| 407 | 407 |
simplecov (0.9.2) |
| 408 | 408 |
docile (~> 1.1.0) |
| 409 | 409 |
multi_json (~> 1.0) |
@@ -451,17 +451,17 @@ GEM |
||
| 451 | 451 |
builder (>= 2.1.2) |
| 452 | 452 |
jwt (>= 0.1.2) |
| 453 | 453 |
multi_json (>= 1.3.0) |
| 454 |
- twitter (5.8.0) |
|
| 454 |
+ twitter (5.14.0) |
|
| 455 | 455 |
addressable (~> 2.3) |
| 456 | 456 |
buftok (~> 0.2.0) |
| 457 | 457 |
equalizer (~> 0.0.9) |
| 458 | 458 |
faraday (~> 0.9.0) |
| 459 |
- http (~> 0.5.0) |
|
| 459 |
+ http (~> 0.6.0) |
|
| 460 | 460 |
http_parser.rb (~> 0.6.0) |
| 461 | 461 |
json (~> 1.8) |
| 462 | 462 |
memoizable (~> 0.4.0) |
| 463 | 463 |
naught (~> 1.0) |
| 464 |
- simple_oauth (~> 0.2.0) |
|
| 464 |
+ simple_oauth (~> 0.3.0) |
|
| 465 | 465 |
typhoeus (0.6.9) |
| 466 | 466 |
ethon (>= 0.7.1) |
| 467 | 467 |
tzinfo (1.2.2) |
@@ -571,7 +571,7 @@ DEPENDENCIES |
||
| 571 | 571 |
therubyracer (~> 0.12.1) |
| 572 | 572 |
tumblr_client |
| 573 | 573 |
twilio-ruby (~> 3.11.5) |
| 574 |
- twitter (~> 5.8.0) |
|
| 574 |
+ twitter (~> 5.14.0) |
|
| 575 | 575 |
twitter-stream! |
| 576 | 576 |
typhoeus (~> 0.6.3) |
| 577 | 577 |
tzinfo (>= 1.2.0) |
@@ -0,0 +1,15 @@ |
||
| 1 |
+class AgentCheckJob < ActiveJob::Base |
|
| 2 |
+ # Given an Agent id, load the Agent, call #check on it, and then save it with an updated `last_check_at` timestamp. |
|
| 3 |
+ def perform(agent_id) |
|
| 4 |
+ agent = Agent.find(agent_id) |
|
| 5 |
+ begin |
|
| 6 |
+ return if agent.unavailable? |
|
| 7 |
+ agent.check |
|
| 8 |
+ agent.last_check_at = Time.now |
|
| 9 |
+ agent.save! |
|
| 10 |
+ rescue => e |
|
| 11 |
+ agent.error "Exception during check. #{e.message}: #{e.backtrace.join("\n")}"
|
|
| 12 |
+ raise |
|
| 13 |
+ end |
|
| 14 |
+ end |
|
| 15 |
+end |
@@ -0,0 +1,16 @@ |
||
| 1 |
+class AgentReceiveJob < ActiveJob::Base |
|
| 2 |
+ # Given an Agent id and an array of Event ids, load the Agent, call #receive on it with the Event objects, and then |
|
| 3 |
+ # save it with an updated `last_receive_at` timestamp. |
|
| 4 |
+ def perform(agent_id, event_ids) |
|
| 5 |
+ agent = Agent.find(agent_id) |
|
| 6 |
+ begin |
|
| 7 |
+ return if agent.unavailable? |
|
| 8 |
+ agent.receive(Event.where(:id => event_ids).order(:id)) |
|
| 9 |
+ agent.last_receive_at = Time.now |
|
| 10 |
+ agent.save! |
|
| 11 |
+ rescue => e |
|
| 12 |
+ agent.error "Exception during receive. #{e.message}: #{e.backtrace.join("\n")}"
|
|
| 13 |
+ raise |
|
| 14 |
+ end |
|
| 15 |
+ end |
|
| 16 |
+end |
@@ -387,24 +387,11 @@ class Agent < ActiveRecord::Base |
||
| 387 | 387 |
end |
| 388 | 388 |
end |
| 389 | 389 |
|
| 390 |
- # Given an Agent id and an array of Event ids, load the Agent, call #receive on it with the Event objects, and then |
|
| 391 |
- # save it with an updated `last_receive_at` timestamp. |
|
| 392 |
- # |
|
| 393 |
- # This method is tagged with `handle_asynchronously` and will be delayed and run with delayed_job. It accepts Agent |
|
| 394 |
- # and Event ids instead of a literal ActiveRecord models because it is preferable to serialize delayed_jobs with ids. |
|
| 390 |
+ # This method will enqueue an AgentReceiveJob job. It accepts Agent and Event ids instead of a literal ActiveRecord |
|
| 391 |
+ # models because it is preferable to serialize jobs with ids. |
|
| 395 | 392 |
def async_receive(agent_id, event_ids) |
| 396 |
- agent = Agent.find(agent_id) |
|
| 397 |
- begin |
|
| 398 |
- return if agent.unavailable? |
|
| 399 |
- agent.receive(Event.where(:id => event_ids).order(:id)) |
|
| 400 |
- agent.last_receive_at = Time.now |
|
| 401 |
- agent.save! |
|
| 402 |
- rescue => e |
|
| 403 |
- agent.error "Exception during receive. #{e.message}: #{e.backtrace.join("\n")}"
|
|
| 404 |
- raise |
|
| 405 |
- end |
|
| 393 |
+ AgentReceiveJob.perform_later(agent_id, event_ids) |
|
| 406 | 394 |
end |
| 407 |
- handle_asynchronously :async_receive |
|
| 408 | 395 |
|
| 409 | 396 |
# Given a schedule name, run `check` via `bulk_check` on all Agents with that schedule. |
| 410 | 397 |
# This is called by bin/schedule.rb for each schedule in `SCHEDULES`. |
@@ -425,24 +412,11 @@ class Agent < ActiveRecord::Base |
||
| 425 | 412 |
end |
| 426 | 413 |
end |
| 427 | 414 |
|
| 428 |
- # Given an Agent id, load the Agent, call #check on it, and then save it with an updated `last_check_at` timestamp. |
|
| 429 |
- # |
|
| 430 |
- # This method is tagged with `handle_asynchronously` and will be delayed and run with delayed_job. It accepts an Agent |
|
| 431 |
- # id instead of a literal Agent because it is preferable to serialize delayed_jobs with ids, instead of with the full |
|
| 432 |
- # Agents. |
|
| 415 |
+ # This method will enqueue an AgentCheckJob job. It accepts an Agent id instead of a literal Agent because it is |
|
| 416 |
+ # preferable to serialize job with ids, instead of with the full Agents. |
|
| 433 | 417 |
def async_check(agent_id) |
| 434 |
- agent = Agent.find(agent_id) |
|
| 435 |
- begin |
|
| 436 |
- return if agent.unavailable? |
|
| 437 |
- agent.check |
|
| 438 |
- agent.last_check_at = Time.now |
|
| 439 |
- agent.save! |
|
| 440 |
- rescue => e |
|
| 441 |
- agent.error "Exception during check. #{e.message}: #{e.backtrace.join("\n")}"
|
|
| 442 |
- raise |
|
| 443 |
- end |
|
| 418 |
+ AgentCheckJob.perform_later(agent_id) |
|
| 444 | 419 |
end |
| 445 |
- handle_asynchronously :async_check |
|
| 446 | 420 |
end |
| 447 | 421 |
end |
| 448 | 422 |
|
@@ -35,7 +35,7 @@ module Agents |
||
| 35 | 35 |
incoming_events.each do |event| |
| 36 | 36 |
log "Sending digest mail to #{user.email} with event #{event.id}"
|
| 37 | 37 |
recipients(event.payload).each do |recipient| |
| 38 |
- SystemMailer.delay.send_message(:to => recipient, :subject => interpolated(event)['subject'], :headline => interpolated(event)['headline'], :body => interpolated(event)['body'], :groups => [present(event.payload)]) |
|
| 38 |
+ SystemMailer.send_message(:to => recipient, :subject => interpolated(event)['subject'], :headline => interpolated(event)['headline'], :body => interpolated(event)['body'], :groups => [present(event.payload)]).deliver_later |
|
| 39 | 39 |
end |
| 40 | 40 |
end |
| 41 | 41 |
end |
@@ -42,7 +42,7 @@ module Agents |
||
| 42 | 42 |
groups = self.memory['queue'].map { |payload| present(payload) }
|
| 43 | 43 |
log "Sending digest mail to #{user.email} with events [#{ids}]"
|
| 44 | 44 |
recipients.each do |recipient| |
| 45 |
- SystemMailer.delay.send_message(:to => recipient, :subject => interpolated['subject'], :headline => interpolated['headline'], :groups => groups) |
|
| 45 |
+ SystemMailer.send_message(:to => recipient, :subject => interpolated['subject'], :headline => interpolated['headline'], :groups => groups).deliver_later |
|
| 46 | 46 |
end |
| 47 | 47 |
self.memory['queue'] = [] |
| 48 | 48 |
self.memory['events'] = [] |
@@ -13,7 +13,7 @@ module Huginn |
||
| 13 | 13 |
# -- all .rb files in that directory are automatically loaded. |
| 14 | 14 |
|
| 15 | 15 |
# Custom directories with classes and modules you want to be autoloadable. |
| 16 |
- config.autoload_paths += %W(#{config.root}/lib #{config.root}/app/presenters)
|
|
| 16 |
+ config.autoload_paths += %W(#{config.root}/lib #{config.root}/app/presenters #{config.root}/app/jobs)
|
|
| 17 | 17 |
|
| 18 | 18 |
# Activate observers that should always be running. |
| 19 | 19 |
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer |
@@ -52,5 +52,7 @@ module Huginn |
||
| 52 | 52 |
|
| 53 | 53 |
# Do not swallow errors in after_commit/after_rollback callbacks. |
| 54 | 54 |
config.active_record.raise_in_transactional_callbacks = true |
| 55 |
+ |
|
| 56 |
+ config.active_job.queue_adapter = :delayed_job |
|
| 55 | 57 |
end |
| 56 | 58 |
end |